package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AddressDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 坐标相关
 */
@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {

    //自动注入dao层
    @Autowired
    private AddressDao addressDao;


    /**
     * 查询所有的坐标信息
     * @return
     */
    @Override
    public List<Address> findAddressAll() {

        //调用dao层的方法，查询
        return addressDao.findAddressAll();
    }

    /**
     * 分页查询，查询所有坐标数据
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        //获取分页查询的数据
        Integer currentPage = queryPageBean.getCurrentPage();   //当前页码
        Integer pageSize = queryPageBean.getPageSize();     //当前页面显示的条数
        String queryString = queryPageBean.getQueryString();    //模糊查询条件

        //开始分页查询
        PageHelper.startPage(currentPage,pageSize);

        //进行模糊查询
        Page<Address> page = addressDao.findPageByString(queryString);

        //返回分页查询的数据
        return new PageResult(page.getTotal(),page.getResult());

    }


    /**
     * 根据id删除坐标
     * @param id
     */
    @Override
    public void delAddressById(Integer id) {

        addressDao.delAddressById(id);

    }


    //添加坐标信息到数据库
    @Override
    public void addAddress(Address address) {
        //调用dao层的方法添加坐标信息
        addressDao.addAddress(address);
    }
}
